﻿namespace MicroCloud.AspNetCore.SignalR.Internal
{
    /// <summary>
    /// 类型化Hub客户端
    /// </summary>
    /// <typeparam name="T"></typeparam>
    internal class TypedHubClients<T> : IHubCallerClients<T>, IHubClients<T>
    {
        //字段
        private readonly IHubCallerClients _hubClients;

        #region "属性"
        #region "获取 所有连接的客户端"
        /// <summary>
        /// 获取 所有连接的客户端
        /// </summary>
        public T All
        {
            get
            {
                return TypedClientBuilder<T>.Build(_hubClients.All);
            }
        }
        #endregion
        #region "获取 调用集线器方法的客户端"
        /// <summary>
        /// 获取 调用集线器方法的客户端
        /// </summary>
        public T Caller
        {
            get
            {
                return TypedClientBuilder<T>.Build(_hubClients.Caller);
            }
        }
        #endregion
        #region "获取 除当前连接外的所有客户端"
        /// <summary>
        /// 获取 除当前连接外的所有客户端
        /// </summary>
        public T Others
        {
            get
            {
                return TypedClientBuilder<T>.Build(_hubClients.Others);
            }
        }
        #endregion

        #endregion

        #region "构造函数"
        #region "初始化一个类型化Hub客户端的新实例"
        /// <summary>
        /// 初始化一个类型化Hub客户端 <see cref="TypedHubClients{T}"/> 的新实例
        /// </summary>
        /// <param name="dynamicContext"></param>
        public TypedHubClients(IHubCallerClients dynamicContext)
        {
            _hubClients = dynamicContext;
        }
        #endregion

        #endregion

        #region "方法"
        #region "所有连接的客户端（指定的连接除外）"
        /// <summary>
        /// 所有连接的客户端（指定的连接除外）
        /// </summary>
        /// <param name="excludedConnectionIds">要排除的多个连接</param>
        /// <returns></returns>
        public T AllExcept(IReadOnlyList<string> excludedConnectionIds)
        {
            return TypedClientBuilder<T>.Build(_hubClients.AllExcept(excludedConnectionIds));
        }
        #endregion
        #region "指定连接的客户端"
        /// <summary>
        /// 指定连接的客户端
        /// </summary>
        /// <param name="connectionId">指定连接</param>
        /// <returns></returns>
        public T Client(string connectionId)
        {
            return TypedClientBuilder<T>.Build(_hubClients.Client(connectionId));
        }
        #endregion
        #region "指定名称的组的客户端"
        /// <summary>
        /// 指定名称的组的客户端
        /// </summary>
        /// <param name="groupName">组名称</param>
        /// <returns></returns>
        public T Group(string groupName)
        {
            return TypedClientBuilder<T>.Build(_hubClients.Group(groupName));
        }
        #endregion
        #region "指定名称的组并排除指定连接的客户端"
        /// <summary>
        /// 指定名称的组并排除指定连接的客户端
        /// </summary>
        /// <param name="groupName">组名称</param>
        /// <param name="excludedConnectionIds">排除的连接</param>
        /// <returns></returns>
        public T GroupExcept(string groupName, IReadOnlyList<string> excludedConnectionIds)
        {
            return TypedClientBuilder<T>.Build(_hubClients.GroupExcept(groupName, excludedConnectionIds));
        }
        #endregion
        #region "指定连接的多个客户端"
        /// <summary>
        /// 指定连接的多个客户端
        /// </summary>
        /// <param name="connectionIds"></param>
        /// <returns></returns>
        public T Clients(IReadOnlyList<string> connectionIds)
        {
            return TypedClientBuilder<T>.Build(_hubClients.Clients(connectionIds));
        }
        #endregion
        #region "指定名称的多个组的客户端"
        /// <summary>
        /// 指定名称的多个组的客户端
        /// </summary>
        /// <param name="groupNames">多个组名称</param>
        /// <returns></returns>
        public T Groups(IReadOnlyList<string> groupNames)
        {
            return TypedClientBuilder<T>.Build(_hubClients.Groups(groupNames));
        }
        #endregion
        #region "一个组中的客户端，不包括调用该集线器方法的客户端"
        /// <summary>
        /// 一个组中的客户端，不包括调用该集线器方法的客户端
        /// </summary>
        /// <param name="groupName">组名称</param>
        /// <returns></returns>
        public T OthersInGroup(string groupName)
        {
            return TypedClientBuilder<T>.Build(_hubClients.OthersInGroup(groupName));
        }
        #endregion
        #region "指定用户的客户端"
        /// <summary>
        /// 指定用户的客户端
        /// </summary>
        /// <param name="userId">用户标识</param>
        /// <returns></returns>
        public T User(string userId)
        {
            return TypedClientBuilder<T>.Build(_hubClients.User(userId));
        }
        #endregion
        #region "指定的多个用户的客户端"
        /// <summary>
        /// 指定的多个用户的客户端
        /// </summary>
        /// <param name="userIds">多个用户标识</param>
        /// <returns></returns>
        public T Users(IReadOnlyList<string> userIds)
        {
            return TypedClientBuilder<T>.Build(_hubClients.Users(userIds));
        }
        #endregion

        #endregion

    }
}
